<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org/">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>课程类别管理</title>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.css" th:href="@{/css/bootstrap.css}" />
    <link rel="stylesheet" type="text/css" href="/css/back-index.css" th:href="@{/css/back-index.css}" />
    <script src="/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/bootstrap-paginator.js"></script>
    <script src="/js/bootstrap-mypaginator.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(function(){
            $("#doAddCourseType").on("click", function() {
				$(".modal-title").html("添加类别");
                $("#courseType-id-input").hide();
                $("#courseTypeModal").modal("show");
            });
            $(".courseType-btn").on("click", function() {
                $("#courseTypeModal").modal("hide");
            });

            $(".courseType-modify").on("click", function() {
				$(".modal-title").html("修改类别");
                $("#courseType-id-input").show();
                $("#courseTypeModal").modal("show");
            });

            //查询子类别
            $(".course-type-detail").on("click", function() {
                $('#frame-id', window.parent.document).attr('src', 'back_courseTypeSet.html');
            });
            //返回父类别列表页面
            $("#back").on("click", function() {
                $('#frame-id', window.parent.document).attr('src', 'back_courseTypeSet.html');
            });


            //分页
            let options={
                bootstrapMajorVersion:3,
                // currentPage:"${session.pageUsers.pageNum==0?1:session.pageUsers.pageNum}",
                currentPage:[[${pageCourses.pageNum}]]==0?1:[[${pageCourses.pageNum}]],
                // totalPages:"${pageUsers.pages==0?1:pageUsers.pages}",
                totalPages:[[${pageCourses.pages}]]==0?1:[[${pageCourses.pages}]],
                pageSize:[[${pageCourses.pageSize}]],
                alignment: "center",
                pagination:true,
                pageUrl:function (type,page,current) {
                    return "/courseType/showCourseTypes?pageNo="+page;
                }


            }
            $("#myPages").bootstrapPaginator(options);
            
        });

        function addCourseType() {
            $.ajax({
                type:"post",
                url: "/courseType/addCourseType ",
                data: {"courseTypeName":$("#courseType-name").val()},
                success:function (response) {
                    if (response.status==1){
                        alert(response.message)
                    }
                }
            })
        }
        function modifyStatus(courseId) {
            $.ajax({
                type: "post",
                url: "/courseType/modifyStatus",
                data: {"courseId":courseId},
                success:function (response) {
                    if (response.status==1){
                        location.href="/courseType/showCourseTypes?pageNo="+[[${pageNo}]];
                    }
                }
            })
        }
    </script>


</head>

<body>

    <!-- 课程类别管理 -->
    <div class="panel panel-default" id="departmentSet">
        <div class="panel-heading">
            <h3 class="panel-title">课程类别管理</h3>
        </div>
        <div class="panel-body">
            <input type="button" value="添加课程类别" class="btn btn-primary" id="doAddCourseType" />
            <!-- courseType父类别id,没有时,移除此按钮 -->
            <input type="hidden" name="parent_id" value=""  />
            <input type="button" value="返回上级列表" class="btn btn-success" id="back" style="float: right;" />
            <br>
            <br>
            <div class="modal fade" tabindex="-1" id="courseTypeModal">
                <!-- 窗口声明 -->
                <div class="modal-dialog modal-lg">
                    <!-- 内容声明 -->
                    <div class="modal-content">
                        <!-- 头部、主体、脚注 -->
                        <div class="modal-header">
                            <button class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">添加类别</h4>
                        </div>
                        <div class="modal-body text-center">
                            <div class="row text-right" id="courseType-id-input" >
                                <label for="courseType-id" class="col-sm-4 control-label">编号：</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="courseType-id" readonly="true" />
                                </div>
                            </div>
                            <br>
                            <div class="row text-right">
                                <label for="courseType-name" class="col-sm-4 control-label">类别名称：</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="courseType-name" />
                                </div>
                            </div>
                            <br>
                        </div>
                        <div class="modal-footer">
                            <input class="btn btn-primary courseType-btn" value="确定" id="add-true" onclick="addCourseType()"></input>
                            <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="show-list">
                <table class="table table-bordered table-hover" style='text-align: center;'>
                    <thead>
                        <tr class="text-danger">
                            <th class="text-center">编号</th>
                            <th class="text-center">名称</th>
                            <th class="text-center">状态</th>
                            <th class="text-center">操作</th>
                        </tr>
                    </thead>
                    <tbody id="tb" th:foreach="courseType:${typePageInfo}">
                        <tr>
                            <td th:text="${courseType.id}">2</td>

                            <td th:text="${courseType.typeName}">IOS</td>
                            <td th:text="${courseType.status}==1?'启用':'禁用'"></td>
                            <td>
                                <input type="button" class="btn btn-warning btn-sm courseType-modify" value="修改" />
                                <input type="button" th:class="${courseType.status}==1?'btn btn-warning btn-sm':'btn btn-success btn-sm'"
                                       th:text="${courseType.status}==1?'禁用':'启用'"
                                th:onclick="|javascript:modifyStatus(${courseType.id})|"/>
                                <input type="button" class="btn btn-success btn-sm course-type-detail" value="查询子类别" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            <div style="text-align: center;" >
                <ul id="myPages" ></ul>
            </div>
        </div>
    </div>
</body>

</html>